/**
 * 全局常量过滤器
 * @parmas val 过滤器默认传入的值
 * @parmas constantList 常量数组
 * @parmas key 返回常量对应的key
 * */
export function constFilter(
	val: any,
	constantList: any[],
	key = "label",
	valKey = "value"
): string | number {
	if (!val || !constantList || constantList.length == 0) {
		// (!val || !constantList) && console.error("传入过滤器的值不正确！");
		return "";
	}

	const newVal = constantList?.find((e: any) => e[valKey] == val);
	return newVal && newVal[key];
}

// 保留小数
export function toFixed(val: string | number, num = 2): string | number {
	if (!val || val == Infinity) return 0;
	return Number(val)
		.toFixed(num)
		.replace(/(\d)(\.00)/, "$1");
}

declare interface Constant {
	label: number | string;
	value: number | string;
	[key: string]: any;
}

// 模块常量
export const ROLE_LIST: Constant[] = [
	{ label: "货主", value: "hz", folw: "", status: '' },
	{ label: "仓管", value: "cg", folw: "4,5", status: '4' },
	{ label: "吊装", value: "dz", folw: "5", status: '5' },
	{ label: "财务", value: "cw", folw: "1,2,3,4,5", status: '1' },
	{ label: "总经理", value: "zjl", folw: "1,2,3,4,5", status: '2' },
];


// 审核状态
export const FLOW_STATUS: Constant[] = [
	{ label: "财务审核中", value: 1, color: "warning" },
	{ label: "总经理审核中", value: 2, color: "warning" },
	{ label: "等待发起服务", value: 3, color: "success" },
	{ label: "仓管确认中", value: 4, color: "error" },
	{ label: "吊装确认中", value: 5, color: "primary" },
	{ label: "已完成", value: 6, color: "info" },
];

// 报表荒料筛选
export const  REPORT_HL_FILTER: Constant[] = [
	{
		label: '物料名称筛选',
		value: 'mtlName',
		default: '',
		type: 'input',
	},
	{
		label: '荒料号筛选',
		value: 'blockNo',
		default: '',
		type: 'input',
	},
	{
		label: '仓库筛选',
		value: 'whsName',
		default: '',
		type: 'input',
	},
	{
		label: '库区筛选',
		value: 'storeAreaName',
		default: '',
		type: 'input',
	},
	{
		label: '储位筛选',
		value: 'locationName',
		default: '',
		type: 'input',
	},
	{
		label: '长度筛选类型', // 1 大于 2 等于 3小玉 0 不筛选 
		value: 'lengthType',
		default: 0,
		type: 'select',
		selData: [
			{
				label: '默认',
				value: 0
			},
			{
				label: '大于',
				value: 1
			},
			{
				label: '等于',
				value: 2
			},
			{
				label: '小于',
				value: 0
			},
		]
	},
	{
		label: '长度筛选',
		value: 'length',
		default: 0,
		type: 'input',
	},
	{
		label: '宽度筛选类型', // 1 大于 2 等于 3小玉 0 不筛选 
		value: 'widthType',
		default: 0,
		type: 'select',
		selData: [
			{
				label: '默认',
				value: 0
			},
			{
				label: '大于',
				value: 1
			},
			{
				label: '等于',
				value: 2
			},
			{
				label: '小于',
				value: 0
			},
		]
	},
	{
		label: '宽度筛选',
		value: 'width',
		default: 0,
		type: 'input',
	},
	// {
	// 	label: '物料名称筛选',
	// 	value: 'mtlName',
	// 	default: '',
	// 	type: 'input',
	// },
	// {
	// 	label: '物料名称筛选(多个)',
	// 	value: 'mtlNames',
	// 	default: '',
	// 	type: 'input',
	// },
]